package com.derbysoft.ota.application.translator.rq;

import com.derbysoft.modules.eip.translator.Translator;
import com.derbysoft.remote.dswitch.generic.constants.CardCode;
import com.google.inject.internal.Preconditions;
import com.googlecode.functionalcollections.FunctionalIterable;
import com.googlecode.functionalcollections.FunctionalIterables;


public class CardCodeTranslator implements Translator<String, CardCode> {

	private static final String AX = "AX";

	@Override
	public CardCode translate(String source) {
		if (AX.equals(source)) {
			return CardCode.AMERICAN_EXPRESS;
		}
		return Preconditions.checkNotNull(
			CardCode.fromCode(source), 
			"Unsupported PaymentCardCodeType [" + source + "], " 
				+ "supported values are taken from PaymentCardCodeType in OTA_SimpleTypes.xsd : " 
				+ supportedValues()
		);
	}

	private FunctionalIterable<String> supportedValues() {
		return FunctionalIterables.<String>create()
									.concat(AX)
									.concat("BC")
									.concat("BL")
									.concat("CB")
									.concat("DN")
									.concat("DS")
									.concat("EC")
									.concat("JC")
									.concat("MA")
									.concat("MC")
									.concat("TP")
									.concat("VI");
	}

}
